%{ /* C declarations used in actions */
    #include <stdio.h>
    #include "eval-upmc.h"
    #include "y.tab.h"
    
    extern int yyparse();
    extern int yylex();
    extern int yylineno;
    extern int yytext;
    
    void yyerror (char *s);
    %}

/* yacc definitions */

%left PLUS  MOINS
%left FOIS  DIVISE
%left NEG

%token <number> ENTIER
%token <dbl> REEL
%token  PLUS  MOINS FOIS  DIVISE NEG
%token  PARENTHESE_GAUCHE PARENTHESE_DROITE
%union {int number; double dbl; ast_st* ast;}
%start Input

%type <ast> Input Expression

%%


Input:
'{' Expression '}'            { return $2; }
;

Expression   :
ENTIER                {$$ = create_integer($1);}
| REEL                 {$$ = create_real($1);}
| Expression PLUS Expression  { $$=create_node(Plus, $1, $3); }
| Expression MOINS Expression { $$=create_node(Moins, $1, $3); }
| Expression FOIS Expression  { $$=create_node(Fois, $1, $3); }
| Expression DIVISE Expression  { $$=create_node(Divise, $1, $3); }
| MOINS Expression %prec NEG  { $$=create_node(Fois, $2, create_integer(-1)); }
| PARENTHESE_GAUCHE Expression PARENTHESE_DROITE  { $$=$2; }
;

%%

void yyerror (char *s) {
    fprintf (stderr, "Error: '%s' at '%s'\n", s, yytext);
}
